package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.service.SpecParamService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author ：qcq
 * @date ：Created in 2020/12/6 14:18
 * @description：规格参数业务层
 */
@Service
public class SpecParamServiceImpl extends ServiceImpl<SpecParamMapper, SpecParam> implements SpecParamService {

    @Override
    public List<SpecParamDTO> querySpecParam(Long categoryId, Long groupId, Boolean searching) {
        List<SpecParam> specParams = this.query().eq((categoryId != null), "category_id", categoryId)
                .eq((groupId != null),"group_id", groupId)
                .eq((searching != null),"searching", searching).list();
        List<SpecParamDTO> specParamDTOList = SpecParamDTO.convertEntityList(specParams);
        return specParamDTOList;
    }

    @Override
    @Transactional
    public void updateSpecParam(SpecParamDTO specParamDTO) {
        SpecParam specParam = specParamDTO.toEntity(SpecParam.class);
        this.updateById(specParam);
    }

    @Override
    @Transactional
    public void addSpecParam(SpecParamDTO specParamDTO) {
        SpecParam specParam = specParamDTO.toEntity(SpecParam.class);
        this.save(specParam);
    }
}
